package com.air.leetcode;

import io.swagger.models.auth.In;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 剑指offer 03
 * 原地交换算法
 *
 * @author shent
 */
public class Test1 {
    public static void main(String[] args) {
        System.out.println(findRepeatNumber(new int[]{2, 3, 5, 1, 0, 5, 4}));
    }

    public static int findRepeatNumber(int[] nums) {
        int i = 0;
        while (i < nums.length) {
            if (nums[i] == i) {
                i++;
                continue;
            }
            if (nums[nums[i]] == nums[i]) {
                return nums[i];
            }
            int tmp = nums[i];
            nums[i] = nums[tmp];
            nums[tmp] = tmp;
        }
        return -1;
    }
}
